/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.persistence.spring.dependency.impl;

import com.genia.toolbox.basics.exception.BundledException;
import com.genia.toolbox.persistence.dao.AbstractDAO;
import com.genia.toolbox.persistence.spring.dependency.PersistableDependency;

/**
 * the default implementation for <code>PersistableDependency</code>.
 * 
 * @param <TYPE>
 *          the type of the object this interface handles the dependencies
 */
public abstract class AbstractPersistableDependency<TYPE>
    extends AbstractDAO
    implements PersistableDependency<TYPE>
{

  /**
   * the base type of the object handled by this class.
   */
  private final transient Class<TYPE> type;

  /**
   * the order in which this dependency must be executed. By default, it is
   * <code>0</code>.
   */
  private int order = 0;



  /**
   * Constructor.
   * 
   * @param type
   *          the base type of the object handled by this class
   */
  protected AbstractPersistableDependency(final Class<TYPE> type)
  {
    this.type = type;
  }



  /**
   * return the order in which this dependency must be executed. By default,
   * return <code>0</code>.
   * 
   * @return the order in which this dependency must be executed
   */
  public int getOrder()
  {
    return order;
  }



  /**
   * Return the base type of the object handled by this class.
   * 
   * @return the base type of the object handled by this class
   */
  public Class<TYPE> getType()
  {
    return type;
  }



  /**
   * handle the dependencies before updating an object.
   * 
   * @param object
   *          the object that will be updated
   * @throws BundledException
   *           when an error occurs
   */
  public void onUpdate(final TYPE object)
      throws BundledException
  {
    // Do nothing.
  }



  /**
   * handle the dependencies before creating an object.
   * 
   * @param object
   *          the object that will be created
   * @throws BundledException
   *           when an error occurs
   */
  public void onCreate(final TYPE object)
      throws BundledException
  {
    // Do nothing.
  }



  /**
   * handle the dependencies after creating an object.
   * 
   * @param object
   *          the object that has been created
   * @throws BundledException
   *           when an error occurs
   */
  public void onPostCreate(final TYPE object)
      throws BundledException
  {
    // Do nothing.
  }



  /**
   * handle the dependencies after updating an object.
   * 
   * @param object
   *          the object that has been created
   * @throws BundledException
   *           when an error occurs
   */
  public void onPostUpdate(final TYPE object)
      throws BundledException
  {
    // Do nothing.
  }



  /**
   * handle the dependencies before deleting an object.
   * 
   * @param object
   *          the object that will be deleted when an error occurs
   * @throws BundledException
   *           when an error occurred
   */
  public void onDelete(final TYPE object)
      throws BundledException
  {
    // Do nothing.
  }



  /**
   * setter for the order property.
   * 
   * @param order
   *          the order to set
   */
  public void setOrder(final int order)
  {
    this.order = order;
  }

}
